package com.rainng.coursesystem.service;

import com.rainng.coursesystem.model.NotificationItem;
import com.rainng.coursesystem.repository.NotificationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NotificationService {

    @Autowired
    private NotificationRepository notificationRepository;

    public List<NotificationItem> getAllNotifications() {
        return notificationRepository.findAllByOrderByCreatedAtDesc();
    }

    public NotificationItem createNotification(NotificationItem notification) {
        notification.setCreatedAt(LocalDateTime.now());
        return notificationRepository.save(notification);
    }

    public void deleteNotification(Long id) {
        notificationRepository.deleteById(id);
    }
}